home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MonitorDoubler / Source / GDeviceUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.8 KB  |  255 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    GDeviceUtils.h
  4. #
  5. #    by Eric Traut
  6. #
  7. ------------------------------------------------------------------------------*/
  8.  
  9. #include <Types.h>
  10. #include <QDOffscreen.h>
  11. #include <Displays.h>
  12.  
  13. // GraphicSurface
  14. // This class encapsulates a blitting surface, specifying
  15. // its base pointer, depth, dimensions and rowBytes values.
  16. // The actual surface may be real or virtual. In many ways,
  17. // it's comparable to a GWorld in the Mac toolbox.
  18. class GraphicSurface
  19. {
  20.     public:
  21.         GraphicSurface();
  22.         
  23.         void
  24.         ExtractRealDeviceInfo(
  25.             GDHandle            inGDevice);
  26.         
  27.         UInt16
  28.         GetRowBytes() const
  29.         {
  30.             return mRowBytes;
  31.         }
  32.         
  33.         UInt8 *
  34.         GetPixelDataPtr() const
  35.         {
  36.             return mPixelData;
  37.         }
  38.         
  39.         UInt16
  40.         GetBitDepth() const
  41.         {
  42.             return mBitDepth;
  43.         }
  44.         
  45.         UInt16
  46.         GetHeight() const
  47.         {
  48.             return mHeight;
  49.         }
  50.         
  51.         UInt16
  52.         GetWidth() const
  53.         {
  54.             return mWidth;
  55.         }
  56.         
  57.         UInt32
  58.         GetBackingSize() const
  59.         {
  60.             // Allocate two extra scan lines for some slop
  61.             return GetRowBytes() * (GetHeight() + 2);
  62.         }
  63.         
  64.     private:
  65.         UInt16            mRowBytes;
  66.         UInt8 *            mPixelData;
  67.         UInt16            mBitDepth;
  68.         UInt16            mHeight;
  69.         UInt16            mWidth;
  70. };
  71.  
  72.  
  73. class VirtualGDevice;
  74.  
  75. class GraphicBlendEffect
  76. {
  77.     public:
  78.         GraphicBlendEffect()
  79.         {
  80.         }
  81.         
  82.         virtual
  83.         ~GraphicBlendEffect()
  84.         {
  85.         }
  86.  
  87.         virtual Boolean
  88.         Initialize()
  89.         {
  90.             return true;
  91.         }
  92.         
  93.         virtual void
  94.         RenderVirtualDevice(
  95.             const GraphicSurface &    inDestSurface,
  96.             VirtualGDevice *        inVDevice) = 0;
  97. };
  98.  
  99.  
  100. class LargeBlendEffect : public GraphicBlendEffect
  101. {
  102.     public:
  103.         enum
  104.         {
  105.             kCircleWidth = 128
  106.         };
  107.         
  108.         LargeBlendEffect();
  109.         
  110.         UInt16
  111.         AveragePixels(
  112.             UInt16        inPixel1,
  113.             UInt16        inPixel2,
  114.             UInt16        inPixel3,
  115.             UInt16        inPixel4);
  116.  
  117.         void
  118.         EnableMagnify(
  119.             Boolean                inEnable)
  120.         {
  121.             mMagnify = inEnable;
  122.         }
  123.  
  124.         virtual void
  125.         RenderVirtualDevice(
  126.             const GraphicSurface &    inDestSurface,
  127.             VirtualGDevice *        inVDevice);
  128.  
  129.         UInt16
  130.         BlendPixels(
  131.             UInt16        inPixel1,
  132.             UInt16        inPixel2,
  133.             UInt32        inFraction);
  134.  
  135.     private:
  136.         Handle            mCircleData;
  137.         Boolean            mMagnify;
  138. };
  139.  
  140.  
  141. // CapturedGDevice
  142. // This class allows us to "capture" an existing GDevice (monitor).
  143. class CapturedGDevice
  144. {
  145.     public:
  146.         CapturedGDevice();
  147.         
  148.         virtual
  149.         ~CapturedGDevice();
  150.         
  151.         void
  152.         CaptureDevice(
  153.             GDHandle            inGDevice,
  154.             VirtualGDevice *    inVDevice);
  155.         
  156.         void
  157.         UncaptureDevice();
  158.         
  159.         void
  160.         UpdateCapturedScreen();
  161.         
  162.         void
  163.         RecomputeGDHandle();
  164.         
  165.         GraphicSurface &
  166.         GetGraphicSurface()
  167.         {
  168.             return mCapturedSurface;
  169.         }
  170.         
  171.         void
  172.         SetGraphicBlendEffect(
  173.             GraphicBlendEffect *    inBlendEffect);
  174.         
  175.         void
  176.         SetGraphicBlendValue(
  177.             UInt32                    inValueIndex,
  178.             double                    inValue);
  179.         
  180.         void
  181.         SetPixelBase(
  182.             UInt8 *                inPixelBase);
  183.  
  184.         PixMapHandle
  185.         GetPixMapHandle()
  186.         {
  187.             return mGDHandle[0]->gdPMap;
  188.         }
  189.  
  190.         void
  191.         ClearCapturedScreen();
  192.  
  193.     private:
  194.         GraphicBlendEffect *    mBlendEffect;
  195.         
  196.         GraphicSurface            mCapturedSurface;
  197.         GDHandle                mGDHandle;
  198.         DisplayIDType            mDisplayID;
  199.         Boolean                    mDeviceCaptured;
  200.  
  201.         VirtualGDevice *        mVirtualDevice;
  202. };
  203.  
  204.  
  205. // VirtualGDevice
  206. // This class allows us to create a new "virtual" GDevice, effectively
  207. // adding a monitor to the system. One VirtualGDevice (and one only)
  208. // should be designated the "primary" device. This allows us to make
  209. // use of the existing GWorld handle in the system.
  210. class VirtualGDevice
  211. {
  212.     public:
  213.         VirtualGDevice();
  214.  
  215.         virtual
  216.         ~VirtualGDevice();
  217.     
  218.         Boolean
  219.         Initialize(
  220.             CapturedGDevice &    inRealGDevice,
  221.             Handle                inDMConfigHandle);
  222.  
  223.         void
  224.         Uninitialize();
  225.  
  226.         void
  227.         RecomputeGDHandle();
  228.  
  229.         GraphicSurface &
  230.         GetGraphicSurface()
  231.         {
  232.             return mVirtualSurface;
  233.         }
  234.  
  235.         GDHandle
  236.         GetGDHandle()
  237.         {
  238.             RecomputeGDHandle();
  239.             return mGDHandle;
  240.         }
  241.     
  242.     private:
  243.         GraphicSurface        mVirtualSurface;
  244.         Ptr                    mDeviceBacking;
  245.         Boolean                mAddedToDeviceList;
  246.         GDHandle            mGDHandle;
  247.         DisplayIDType        mDisplayID;
  248. };
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.